feat: Microsoft Agent Framework compatibility and bypass mode#44
Closed
CaddyGlow wants to merge 2 commits intofeat/codex-v0.114.0-integrationfrom
Closed
feat: Microsoft Agent Framework compatibility and bypass mode#44CaddyGlow wants to merge 2 commits intofeat/codex-v0.114.0-integrationfrom
CaddyGlow wants to merge 2 commits intofeat/codex-v0.114.0-integrationfrom
Conversation
6 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends ccproxy’s Codex/OpenAI compatibility layer to better support Microsoft Agent Framework (MSAF) style traffic by making bypass/mock behavior format-aware (OpenAI Chat vs OpenAI Responses vs Anthropic), adding a bypass-mode adapter fallback at plugin factory level, and propagating openai_thinking_xml streaming behavior through the formatter pipeline.
Changes:
- Add OpenAI Responses-format support to the mock handler (including SSE event sequencing) and make the mock adapter resolve target format from
request.state.context.format_chain/ route endpoint. - Add plugin factory bypass-mode support that returns a
MockAdapter(with clear logging/error behavior). - Add
inject_detection_payloadtoggle to Codex config/adapter to prevent Codex CLI detection/template injection for generic OpenAI-compatible clients; propagateopenai_thinking_xmlvia formatter context.
Reviewed changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Dependency lock updates (notably mcp bump and additional wheels). |
| ccproxy/services/mocking/mock_handler.py | Adds OpenAI Responses mock conversion + Responses SSE streaming event sequence; prompt text extraction. |
| ccproxy/services/adapters/mock_adapter.py | Format-aware mock routing (prefers format_chain, falls back to endpoint detection); passes prompt text through. |
| ccproxy/services/adapters/format_adapter.py | Adds streaming configuration and propagates openai_thinking_xml via formatter contextvar. |
| ccproxy/services/factories.py | Wires openai_thinking_xml config into core adapters and mock handler adapters (chat + responses). |
| ccproxy/plugins/codex/config.py | Introduces inject_detection_payload Codex setting. |
| ccproxy/plugins/codex/adapter.py | Skips detection/template injection when configured; preserves user reasoning; removes additional unsupported keys. |
| ccproxy/llms/formatters/context.py | Adds ContextVar helpers for openai_thinking_xml propagation. |
| ccproxy/llms/formatters/openai_to_openai/streams.py | Respects openai_thinking_xml when emitting wrapped thinking blocks in streaming conversions. |
| ccproxy/llms/formatters/openai_to_openai/responses.py | Respects openai_thinking_xml when wrapping thinking blocks in non-streaming conversions. |
| ccproxy/core/plugins/factories.py | Adds bypass-mode factory path that returns MockAdapter + warning log. |
| .ccproxy.codex.msaf.toml.example | Example config for MSAF clients (disables detection payload injection, disables thinking XML). |
| tests/unit/services/test_mock_adapter.py | Verifies target format resolution via format_chain and endpoint fallback. |
| tests/unit/services/mocking/test_mock_handler.py | Adds tests for prompt extraction and validates Responses SSE event schema/order. |
| tests/unit/llms/test_llms_streaming_settings.py | Tests openai_thinking_xml propagation + ContextVar task isolation. |
| tests/unit/core/test_provider_factory_bypass.py | Tests bypass-mode factory behavior (warning + clear error without service container). |
| tests/plugins/codex/unit/test_adapter.py | Tests inject_detection_payload=False behavior and reasoning preservation. |
| tests/plugins/codex/integration/test_msaf_real_library.py | Integration coverage for sequential agent-style MSAF flows without CLI injection. |
| tests/plugins/codex/integration/test_msaf_compat.py | Integration coverage for MSAF chat completions compatibility + thinking XML disabled behavior. |
| tests/plugins/codex/integration/test_codex_basic.py | Adds bypass streaming test validating OpenAI Responses SSE events. |
Comments suppressed due to low confidence (1)
ccproxy/services/adapters/mock_adapter.py:116
RequestContextis created with a fixedrequest_id="mock-request". Now that mock streaming for OpenAI Chat/Responses derives event IDs (chatcmpl-*,resp_*,msg_*) andX-Request-IDfromctx.request_id, this makes IDs collide across requests in bypass/mock mode and can break clients that expect uniqueness. Consider deriving the request id from an incoming header (e.g.,X-Request-ID) when present, otherwise generate a unique value (uuid4), and use it consistently for bothhandle_requestandhandle_streaming.
ctx = RequestContext(
request_id="mock-request",
start_time=time.perf_counter(),
logger=structlog.get_logger(__name__),
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ee8fb9d to
fcca265
Compare
a06adec to
9c34087
Compare
Add MSAF-compatible mock response handling and bypass mode infrastructure: - Add OpenAI Responses format support to mock handler with proper SSE events - Add prompt text extraction for context-aware mock responses - Add format-aware mock adapter with target format detection - Add bypass mode to plugin factory with MockAdapter fallback - Add inject_detection_payload config toggle for generic API usage - Add openai_thinking_xml streaming configuration - Add format adapter streaming configuration support - Add MSAF integration and real library tests - Add bypass mode factory tests
fcca265 to
4f9e496
Compare
9c34087 to
40f264e
Compare
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This was referenced Mar 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
inject_detection_payloadconfig toggle for generic OpenAI-compatible API usagePR Stack
This is PR 2 of 3 split from #41. Stacked on #43. Merge in order:
Test plan